package com.example.gateway.util.map;

import java.util.HashMap;

/**
 * 通用Map
 * @author Huzz
 * @created 2021-11-30 10:50
 */
public class CommonModel<T> extends HashMap<Object, Object> {

    public CommonModel() {

    }

    public CommonModel success() {
        return success(200, "成功");
    }

    public CommonModel success(String msg) {
        return success(200, msg);
    }

    public CommonModel success(Integer code, String msg) {
        this.put("code", code);
        this.put("msg", msg);
        return this;
    }

    public CommonModel success(T data) {
        return response(200, data);
    }

    public CommonModel fail() {
        return response(500, "失败");
    }

    public CommonModel fail(String msg) {
        return response(500, msg);
    }

    public CommonModel fail(T data) {
        return response(500, data);
    }

    public CommonModel response(Integer code, String msg) {
        this.put("code", code);
        this.put("msg", msg);
        return this;
    }

    public CommonModel response(Integer code, T data) {
        this.put("code", code);
        this.put("msg", data);
        return this;
    }

    @Override
    public CommonModel put(Object key, Object value) {
        super.put(key, value);
        return this;
    }

}
